﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Win.BLL;
using static LoginFm.Form2;
using Win.Common;
using Win.Model;

namespace LoginFm
{
    public partial class Form1 : Form
    {
        private UserBLL userBLL = new UserBLL();
    
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = userBLL.GetList();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
            f.Show();
        }

        private void button_add_Click(object sender, EventArgs e)
        {
            string username = textBox_username.Text.Trim();
            string passwd = Md5Helper.GetMd5(textBox_passwd.Text);
            userBLL.AddUser(username, passwd);
            dataGridView1.DataSource = userBLL.GetList();
        }

        private void button_del_Click(object sender, EventArgs e)
        {
            var data = dataGridView1.CurrentCell.Value.ToString();
            int id = Convert.ToInt32(data);
            userBLL.DelUser(id);
            dataGridView1.DataSource = userBLL.GetList();
        }

        private void button_select_Click(object sender, EventArgs e)
        {
            string username = textBox_username.Text.Trim();
            string passwd = Md5Helper.GetMd5(textBox_passwd.Text);
            user u = userBLL.GetUser(username, passwd);
            List<user> l = new List<user>();
            l.Add(u);
            dataGridView1.DataSource = l;
        }

        private void button_update_Click(object sender, EventArgs e)
        {
            userBLL.UpdateUser();
            dataGridView1.DataSource = userBLL.GetList();
        }
    }
}
